package com.qf.service.impl;

import com.qf.constant.StrategyConstants;
import com.qf.dfa.SensitiveWordFilter;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
 *@Description:敏感词过滤策略
 *@author:刘哥
 *@Date:86180 2022/10/19 17:46
 */
@Service("dirtywords")
@Slf4j
public class DirtyWordsServiceImpl implements FilterChainService {
    @Autowired
    private PushMsgUtil pushMsgUtil;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块-敏感词过滤策略] 开始执行==========");
        /**
         * 使用DFA算法方式
         */
        //1.获取敏感词的过滤对象
        SensitiveWordFilter sensitiveWordFilter= SensitiveWordFilter.getInstance();
        //2.查看敏感词信息
        int i = sensitiveWordFilter.checkSensitiveWord(standardSubmit.getMessageContent(), 0, sensitiveWordFilter.minMatchType);
        //3.判断敏感词数量
        if (i ==0){
            log.info("[敏感词策略==============敏感词策略执行成功]！！！！！");
            return  true;
        }else {
            log.info("[敏感词策略================敏感词策略执行失败]！！！！");
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            pushMsgUtil.pushReport(standardSubmit, StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            return false;
        }

    }
}
